昨天我們建立了紅寶石礦的基礎配置,今天將深入配置生成規則,讓礦物在正確的位置以正確的方式生成。
步驟 1: 建立放置特徵配置
在 src/main/resources/data/rubymod/worldgen/placed_feature/ 目錄下建立 ruby_ore_placed.json:
json
{
"feature": "rubymod:ruby_ore",
"placement": [
{
"type": "minecraft:count",
"count": 4
},
{
"type": "minecraft:in_square"
},
{
"type": "minecraft:height_range",
"height": {
"type": "minecraft:trapezoid",
"min_inclusive": {
"absolute": -64
},
"max_inclusive": {
"absolute": 32
}
}
},
{
"type": "minecraft:biome"
}
]
}
放置規則詳解
json
{
"type": "minecraft:count",
"count": 4
}
控制每個區塊中嘗試生成的次數
值越高,礦物出現越頻繁
json
{
"type": "minecraft:in_square"
}
將生成位置從區塊中心擴展到整個區塊範圍
3. Height Range 放置器
json
{
"type": "minecraft:height_range",
"height": {
"type": "minecraft:trapezoid",
"min_inclusive": {"absolute": -64},
"max_inclusive": {"absolute": 32}
}
}
trapezoid: 梯形分布,在中間高度生成機率最高
absolute: 絕對座標值
我們的紅寶石將在 Y=-64 到 Y=32 之間生成
json
{
"type": "minecraft:biome"
}
確保只在合適的生物群系中生成
步驟 2: 建立生物群系修改器
在 src/main/resources/data/rubymod/forge/biome_modifier/ 目錄下建立 ruby_ore.json:
json
{
"type": "forge:add_features",
"biomes": "#minecraft:is_overworld",
"features": "rubymod:ruby_ore_placed",
"step": "underground_ores"
}
生物群系修改器解析
type: forge:add_features - 添加特徵到生物群系
biomes: #minecraft:is_overworld - 應用於所有主世界生物群系
features: 引用我們定義的放置特徵
step: underground_ores - 在地下礦石生成階段執行